package io.gitee.thinkbungee.mybatis.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import io.gitee.thinkbungee.bean.ResponseResult;
import io.gitee.thinkbungee.mybatis.entity.TestDicEntity;
import io.gitee.thinkbungee.mybatis.service.TestDicService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.Map;


/**
 * 数组字典
 *
 * @author chenyichang
 * @email 820117089@qq.com
 * @date 2022-05-25 18:25:32
 */
@RestController
@RequestMapping("mybatis/testdic")
public class TestDicController {

    @Autowired
    private TestDicService testDicService;

    /**
     * 列表
     */
    @GetMapping("/list")
    public ResponseResult list(@RequestParam Map<String, Object> params) {
        IPage page = testDicService.queryPage(params);
        return ResponseResult.success(page);
    }

    /**
     * 查
     */
    @GetMapping("/info/{id}")
    public ResponseResult info(@PathVariable("id") Integer Id) {
        TestDicEntity testDic = testDicService.getById(Id);
        return ResponseResult.success(testDic);
    }


    /**
     * 增
     */
    @PostMapping("/save")
    public ResponseResult save(@RequestBody TestDicEntity testDic) {
        testDicService.save(testDic);
        return ResponseResult.success();
    }

    /**
     * 改
     */
    @PostMapping("/update")
    public ResponseResult update(@RequestBody TestDicEntity testDic) {
        testDicService.updateById(testDic);
        return ResponseResult.success();
    }

    /**
     * 删
     */
    @DeleteMapping("/delete")
    public ResponseResult delete(@RequestBody Integer[] ids) {
        testDicService.removeByIds(Arrays.asList(ids));
        return ResponseResult.success();

    }

}
